﻿\subsection{Multiplication, division}

\lstinputlisting[style=customc]{patterns/185_64bit_in_32_env/multdiv/2.c}

\subsubsection{x86}

\lstinputlisting[caption=\Optimizing MSVC 2013 /Ob1,style=customasmx86]{patterns/185_64bit_in_32_env/multdiv/2_MSVC_EN.asm}

Multiplication and division are more complex operations, so usually the compiler embeds calls to
a library functions doing that.

These functions are described here: \myref{sec:MSVC_library_func}.

\lstinputlisting[caption=\Optimizing GCC 4.8.1 -fno-inline,style=customasmx86]{patterns/185_64bit_in_32_env/multdiv/2_GCC_EN.asm}

GCC does the expected, but the multiplication
code is inlined right in the function, thinking it could be more efficient.
GCC has different library function names: \myref{sec:GCC_library_func}.

\subsubsection{ARM}

Keil for Thumb mode inserts library subroutine calls:

\lstinputlisting[caption=\OptimizingKeilVI (\ThumbMode),style=customasmARM]{patterns/185_64bit_in_32_env/multdiv/Keil_thumb_O3.s}

Keil for ARM mode, on the other hand, is able to produce 64-bit multiplication code:

\lstinputlisting[caption=\OptimizingKeilVI (\ARMMode),style=customasmARM]{patterns/185_64bit_in_32_env/multdiv/Keil_ARM_O3.s}
% TODO add explanation

\subsubsection{MIPS}

\Optimizing GCC for MIPS can generate 64-bit multiplication code, but has to call a library routine for 64-bit division:

\lstinputlisting[caption=\Optimizing GCC 4.4.5 (IDA),style=customasmMIPS]{patterns/185_64bit_in_32_env/multdiv/MIPS_O3_IDA.lst}

There are a lot of \ac{NOP}s, probably delay slots filled after the multiplication instruction (it's slower
than other instructions, after all).

% TODO add explanation
